package com.jcli._socket基恩士客户端;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class CloseWindowPrompt {
    public static void main(String[] args) {
        JFrame frame = new JFrame("Close Window Example");

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                int option = JOptionPane.showConfirmDialog(frame, "Do you want to close this window?", "Close Window", JOptionPane.YES_NO_OPTION);
                if (option == JOptionPane.YES_OPTION) {
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                }else {

                }
            }
        });

        frame.setSize(300, 200);
        frame.setVisible(true);
    }
}